package com.rectcircle.scalatrateset.controller

import akka.actor.{ActorRef, ActorSystem}
import akka.util.Timeout
import akka.pattern.ask
import org.scalatra.{Accepted, FutureSupport}

import scala.concurrent.ExecutionContext
import scala.concurrent.duration._

/**
  * @author Rectcircle
  *         createTime 2016/12/31
  */
class AkkaController(system:ActorSystem, myActor:ActorRef) extends ScalatratestStack  with FutureSupport {
	implicit val timeout = new Timeout(2 seconds)
	protected implicit def executor: ExecutionContext = system.dispatcher
	
	// You'll see the output from this in the browser.
	get("/ask") {
		myActor ? "Do stuff and give me an answer"
	}
	
	// You'll see the output from this in your terminal.
	get("/tell") {
		myActor ! "Hey, you know what?"
		Accepted()
	}
	
}
